
var timer;
Page({

  data: {
    num: 3,
  },
  onLoad: function (options) {
    this.reduce()
    wx.getLocation({
      altitude: 'altitude',
      highAccuracyExpireTime: 0,
      isHighAccuracy: true,
      type: 'type',
      success: (res) => {
        console.log(res);
        var {latitude,longitude} =res;
        var key = "5SHBZ-N3D3I-M4IGS-5Y7DV-RQXEQ-SRBNV";
        var url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}&get_poi=1`;
        wx.request({
          url,
          header: {
            'content-type': 'application/json'
          },
          method: 'GET',
          dataType: 'json',
          responseType: 'text',
          success: (res) => {
            console.log(res);
            var currentCity = res.data.result.address_component.city.slice(0,2);
            wx.setStorageSync('location', currentCity)
          }
        })
      }
    })
  },
  reduce() {

    timer = setTimeout(() => {
      var num = this.data.num;
      if(num>0){
        num--
        this.setData({
          num
        })
        this.reduce()
      }
      else{
        
        wx.navigateTo({
          url: `../index/index`,
        })
      }
    },1000)
  },
  click(){
    clearTimeout(timer)
    wx.navigateTo({
      url:  `../index/index`,
    })
  },
})